package com.zixun.controller;

import com.zixun.model.Article;
import com.zixun.repository.ArticleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Transactional
public class ArticleController {

    @Autowired
    ArticleRepository articleRepository;



    @RequestMapping("getArticleById")
    public Object getArticleById(Integer id){
        return articleRepository.getArticleById(id);
    }

    @RequestMapping("saveArticle")
    public Object saveArticle(String title){
        Article article = new Article();
        article.setTitle(title);
        articleRepository.save(article);
        return article;
    }

    @RequestMapping("getArticle")
    public List<Article> getArticle(){
        List list = articleRepository.findAll();
        return list;
    }

}
